package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.checkerframework.checker.units.qual.Volume;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author 优惠卷模块
 * @since 2023-04-20
 */
@RestController
@RequestMapping("/coupon")
@RequiredArgsConstructor
public class CouponController {

    private  final ICouponService service;

    @PostMapping
    @ApiOperation("新增优惠卷接口")
    public void AddCoupons(@RequestBody @Valid CouponFormDTO couponDetailVO){
        service.AddCoupons(couponDetailVO);
    }

    @GetMapping("/page")
    @ApiOperation("优惠卷分页接口")
    public PageDTO<CouponPageVO> PageCoupons(CouponQuery query){
        return service.PageCoupons(query);
    }

    @PutMapping("/{id}/issue")
    @ApiOperation("发放优惠劵")
    public void  FaCoupons(@RequestBody @Valid CouponIssueFormDTO formDTO){
        service.FaCoupons(formDTO);
    }

    @PutMapping("/{id}/pause")
    @ApiOperation("暂停发放优惠卷")
    public void PauseCoupons(@ApiParam("优惠卷id") @PathVariable("id") Long id){
        service.PauseCoupons(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id进行查询优惠卷")
    public CouponDetailVO IdCoupons(@PathVariable("{id}") Long id){
        return service.IdCoupons(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改优惠卷")
    public void UpdateCoupons(@PathVariable("{id}") Long id){
        service.UpdateCoupons(id);
    }

    @GetMapping()
    @ApiOperation("查询发放中的优惠卷")
    public List<CouponVO> SaveCoupons(){
        return service.SaveCoupons();
    }
}
